﻿@using Orchard.CounterField.Settings
@using Orchard.Utility.Extensions;

@{
    Style.Require("counter");
    Style.Require("counter2");
    Script.Require("jQuery");
    Script.Require("CounterJS");
}
@{
    string Format = Model.Model.Settings.Format;
    string StopValue = Model.Model.FormattedStop;
    string StartValue = Model.Model.FormattedStart;
    if (!string.IsNullOrWhiteSpace(StartValue)) {
        string name = Model.Model.Field.DisplayName;
    <p>
        <span>@T(name):</span>&nbsp; &nbsp;<span class="counter counter-analog">@StartValue</span>

    </p>
    }
}
@using (Script.Foot())
{
    <script>
        var direction = '@Model.Model.Field.Direction';
        @if (!String.IsNullOrWhiteSpace(@StopValue))
        {
           <text>var stop = '@StopValue';</text>
        }
        else
        {
            <text>var stop = '0';</text>
        }

        @if (!String.IsNullOrWhiteSpace(@StartValue))
        {
           <text>var initial = '@StartValue';</text>
        }
        else
        {
            <text>var initial = '0';</text>
        }       
        var interval = '@Model.Model.Settings.Interval';
        var format = '@Format';
        $('.counter').counter({
            direction: direction,
            @if(!String.IsNullOrWhiteSpace(StartValue)){
            <text>format: format,</text>
            }
            initial: initial,
            @if(!String.IsNullOrWhiteSpace(Model.Model.Settings.Interval + "")){
            <text>interval: interval,</text>
            }
            @if(!String.IsNullOrWhiteSpace(Format)){
            <text>format: format,</text>
            }
            stop: stop
        });
    </script>
}
 